#include <iostream>

#include "vendor/hiredis/hiredis.h"

#include "vendor/cpp-hiredis-cluster/include/cluster.h"
#include "vendor/cpp-hiredis-cluster/include/hirediscommand.h"

using namespace std;

#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
int main() {
    // Declare cluster pointer
    static RedisCluster::Cluster<redisContext>::ptr_t cluster_p;
    // Declare pointer to simple hiredis reply structure
    redisReply * reply;
    // Create cluster passing acceptable address and port of one node of the cluster nodes
    cluster_p = RedisCluster::HiredisCommand<>::createCluster( "192.168.1.201", 7401);
    // send command to redis passing created cluster pointer, key which you wish to access in the command
    // and command itself with parameters with printf like syntax
    reply = static_cast<redisReply*>( RedisCluster::HiredisCommand<>::Command( cluster_p, "FOO", "SET %s %s", "FOO", "BAR1" ) );
    // Check reply state and type
    if( reply->type == REDIS_REPLY_STATUS  || reply->type == REDIS_REPLY_ERROR )
    {
        // Process reply
        cout << " Reply to SET FOO BAR " << endl;
        cout << reply->str << endl;
    }


    // free hiredis reply structure
    freeReplyObject( reply );
    // delete cluster by its pointer
    delete cluster_p;
    cout << "Hello, World!" << endl;
    return 0;
}

